|
|
|
|
|
|
|
In all the examples of the SELECT statement used earlier in this chapter, the results of the query were output to a dynaset or a snapshot. Because these recordsets are only temporary, their contents exist only as long as the recordset is open. After a close method is used or the application is terminated, the recordset disappears (although any changes made to the underlying tables are permanent). |
|
|
|
|
|
|
|
|
Sometimes, however, you might want to permanently store the information in the recordset for later use. Do so with the INTO clause of the SELECT statement. With the INTO clause, you specify the name of an output table (and, optionally, the database for the table) in which to store the results. You might want to do this to generate a mailing-list table from your customer list. This mailing-list table can then be accessed by your word processor to perform a mail-merge function or to print mailing labels. Listing C.4, earlier in this chapter, generated such a list in a dynaset. Listing C.17 shows the same basic SELECT statement as was used in Listing C.4, but the new listing uses the INTO clause to store the information in a table. |
|
|
|
|
|
|
|
|
Listing C.17INTO.TXTUsing the INTO Clause to Save Information to a New Table |
|
|
|
|
|
|
|
|
SELECT CS.Firstname & ' ' & CS.Lastname, CS.Address, ZP.City, _
ZP.State, CS.ZIP INTO Mailings FROM Customers AS CS, _
Zipcode IN USZIPS AS ZP WHERE CS.Zip = ZP.Zip |
|
|
|
|
CAUTION
|
|
|
|
|
The table name you specify should be that of a new table. If you specify the name of a table that already exists, that table is overwritten with the output of the SELECT statement. |
|
|
|
|
|
|
|
|
|
|
So far in all of the clauses, you have seen specific values specified. For example, you specified `AL' for a state of 1.25 for a price. But what if you don't know in advance what value you want to use in comparison? Well, this is precisely what parameters are used for in a SQL statement. The parameter is to the SQL statement what a variable is to a program statement. The parameter is a placeholder whose value is assigned by your program before the SQL statement is executed. |
|
|
|
|
|
|
|
|
To use a parameter in your SQL statement, you first have to specify the parameter in the PARAMETERS declaration part of the statement. The PARAMETERS declaration comes before the SELECT or other manipulative clause in the SQL statement. The declaration specifies both the name of the parameter and its data type. The PARAMETERS clause is separated from the rest of the SQL statement by a semicolon. |
|
|
|
|
|